package com.aiju.app;

import android.app.Application;
import android.content.Context;

import com.aiju.utils.L;

/**
 * @version: V1.0
 * @auther: 佐为
 * @date: 2016.8.29
 * @Description: 基础数据管理者
 */
public class DataProviderManager {

    private static Context applicationContext;

    private static IDataProvider mDataProvider;

    public static Context getContext() {
        if (applicationContext != null) {
            return applicationContext;
        } else {
            if (mDataProvider != null && mDataProvider.getContext() != null) {
                applicationContext = mDataProvider.getContext();
            } else {
                applicationContext = getSystemApp();
            }
            return applicationContext;
        }
    }

    public static IDataProvider getDataProvider() {
        return mDataProvider;
    }

    public static void setDataProvider(IDataProvider mDataProvider) {
        DataProviderManager.mDataProvider = mDataProvider;
        L.d("Height:" + mDataProvider.getScreenHeight());
        L.d("Width:" + mDataProvider.getScreenWidth());
    }

    private static Application getSystemApp() {
        try {
            return (Application) Class.forName("android.app.ActivityThread")
                    .getMethod("currentApplication")
                    .invoke(null, (Object[]) null);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
